package com.hjq.fcloud.utils

import android.app.Activity
import android.webkit.WebSettings
import android.webkit.WebView


/**
 * @author : fenghailin
 * Createtime: 2023/3/16
 * 包名：com.bj.subway.utils
 * 说明：公共webview配置
 */
object WebViewConfig {

    fun commonConfig(activity: Activity?, webView: WebView){
        val webSetting = webView.settings
        webSetting.allowFileAccess = false //访问本地文件
        webSetting.layoutAlgorithm = WebSettings.LayoutAlgorithm.NARROW_COLUMNS
        webSetting.setSupportZoom(true)
        webSetting.savePassword = false
        webSetting.builtInZoomControls = true //设置内置的缩放控件。若为false，则该WebView不可缩放
        webSetting.displayZoomControls = true //隐藏原生的缩放控件，默认是true。如果不想显示放大和缩小按钮，将该属性设置为false即可
        webSetting.useWideViewPort = true
        webSetting.setSupportMultipleWindows(false)
        webSetting.setAppCacheEnabled(true)
        webSetting.domStorageEnabled = true
        webSetting.cacheMode = android.webkit.WebSettings.LOAD_NO_CACHE
        webSetting.javaScriptEnabled = true
        webSetting.setGeolocationEnabled(true)
        webSetting.setAppCacheMaxSize(Long.MAX_VALUE)
        webSetting.setAppCachePath(activity?.getDir("appcache", 0)?.getPath())
        webSetting.databasePath = activity?.getDir("databases", 0)?.getPath()
        webSetting.setGeolocationDatabasePath(
            activity?.getDir("geolocation", 0)?.getPath()
        )
        webSetting.pluginState = WebSettings.PluginState.ON_DEMAND
        webSetting.cacheMode = android.webkit.WebSettings.LOAD_CACHE_ELSE_NETWORK
        webSetting.setRenderPriority(WebSettings.RenderPriority.HIGH)
        webSetting.setAllowUniversalAccessFromFileURLs(true)
        // 支持多窗口
        webSetting.setSupportMultipleWindows(true)
        // 开启 DOM storage API 功能
        webSetting.domStorageEnabled = true
        // 开启 Application Caches 功能
        webSetting.setAppCacheEnabled(true)
        //隐藏WebView缩放按钮
        webSetting.displayZoomControls = false
    }
}